<template>
  <a-card :bordered="false" class="aCard">
    <!-- 查询区域 -->
    <div class="search-wrap">
      <a-form-model ref="formRef">
        <div class="search-title">查询条件</div>
        <a-row>
          <a-col :span="6">
            <div style="margin-right: 12px">
              <a-form-model-item prop="bar"
                ><a-input v-model="queryParam.bar" placeholder="请输入英克码" allowClear />
              </a-form-model-item>
            </div>
          </a-col>
          <a-col :span="3" style="margin-top: 5px">
            <a-button @click="searchQuery('yk')" type="primary"> 查询 </a-button>
            <a-button style="margin-left: 10px" @click="searchReset()"> 重置 </a-button>
          </a-col>
          <a-col v-if="qrCodeImageUrl != ''" :span="6">
            <a-row><img :src="qrCodeImageUrl" alt="QR Code"></a-row>
            <a-row><span style="margin-left: 20px;">{{ queryParam.bar }}</span></a-row>
          </a-col>
        </a-row>
      </a-form-model>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExport1()">导出全部</a-button>
      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query
        :fieldList="superFieldList"
        ref="superQueryModal"
        @handleSuperQuery="handleSuperQuery"
      ></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <!-- 处理状态 -->
        <template slot="blState" slot-scope="text, record">
          <a-tag :color="onColor(text.blState, record)">
            {{ getBlState(record.blState) }}
          </a-tag>
          <span></span>
        </template>

        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">补录</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a @click="handleExport(record)">导出</a>
              </a-menu-item>
              <!-- <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item> -->
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <yk-code-modal ref="modalForm" @ok="modalFormOk"></yk-code-modal>
  </a-card>
</template>

<script>
import { mapState, mapGetters } from 'vuex'



import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import YkCodeModal from './modules/YkCodeModal'
import { stateObjToArray } from '@/utils/common.js'
import { deleteAction, getAction, downFile, getFileAccessHttpUrl } from '@/api/manage'

export default {
  name: 'YkCodeList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    YkCodeModal,
  },
  data() {
    return {
      // description: 'wms_bar_bind_order管理页面',
      // 表头
      dataList: [],
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },

        {
          title: '英克码',
          align: 'center',
          dataIndex: 'bar',
        },
        {
          title: '处理状态',
          align: 'center',
          dataIndex: 'blState',
          //筛选条件编辑
          filters: [
            {
              text: '已处理',
              value: '1',
            },
            {
              text: '待处理',
              value: '0',
            },
          ],
          filterMultiple: false,

          onFilter: (value, record) => {
            return record.blState == value
          },
          scopedSlots: { customRender: 'blState' },
        },
        {
          title: 'UDI',
          align: 'center',
          dataIndex: 'udi',
        },
        {
          title: '产品名称',
          align: 'center',
          dataIndex: 'productName',
        },

        {
          title: '产品规格',
          align: 'center',
          dataIndex: 'productSpec',
        },
        {
          title: '所属仓库',
          align: 'center',
          dataIndex: 'wareName',
        },

        {
          title: '创建人',
          align: 'center',
          dataIndex: 'createBy',
        },

        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime',
        },

        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: `/wms/wmsBarBindOrderDetail/deletionInfoList?blState=0`,
        delete: '/wms/wmsBarBindOrderDetail/delete',
        deleteBatch: '/wms/wmsBarBindOrderDetail/deleteBatch',
        // exportXlsUrl: "/wms/wmsBarBindOrder/exportXls",
        // importExcelUrl: "wms/wmsBarBindOrder/importExcel",
      },
      dictOptions: {},
      superFieldList: [],

      qrCodeData: '', // 要生成二维码的字符串数据
      qrCodeImageUrl: '', // 用于显示生成的二维码图片的 URL

    }
  },
  created() {
    this.getSuperFieldList()
  },
  mounted() {
    // this.searchQuery()
  },
  computed: {
    ...mapGetters(['userInfo']),
    ...mapState({
      inOrderStates: (s) => s.order.inOrderStates,
      stateOptions: (s) => {
        return stateObjToArray(s.order.inOrderStates)
      },
      warehouseOptions: (s) => {
        return stateObjToArray(s.dictionary.enableWarehouse)
      },
      enableWarehouse: (s) => s.dictionary.enableWarehouse,
    }),
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    searchReset() {
      this.$set(this.queryParam, 'bar', undefined)
      this.qrCodeImageUrl = ''
    },
    // searchQuery() {
    //   QRCode.toDataURL(this.queryParam.bar)
    //     .then((url) => {
    //       this.qrCodeImageUrl = url;
    //     })
    //     .catch((error) => {
    //       console.error('生成二维码失败', error);
    //     });
    // },

    getBlState(state) {
      if (state == '0') {
        return '待处理'
      } else if (state == '1') {
        return '已处理'
      }
    },
    // 状态颜色
    onColor(text, record) {
      let color = ''
      if (record.blState == '1') {
        color = 'green'
      } else {
        color = 'red'
      }

      return color
    },

    handleExport(e) {
      // console.log('handleExport', e)
      this.handleExportXls('一品一码绑定_' + e.orderNo, { id: e.id, field: '' })
    },
    handleExport1(e) {
      this.handleExportXls('一品一码绑定')
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'bar', text: '英克码' })
      fieldList.push({ type: 'string', value: 'wareName', text: '所属仓库' })
      fieldList.push({ type: 'string', value: 'udi', text: 'UDI' })
      fieldList.push({ type: 'string', value: 'productSpec', text: '规格' })
      fieldList.push({ type: 'string', value: 'createBy', text: '创建人' })
      this.superFieldList = fieldList
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
.search-title {
  font-size: 16px;
  font-weight: 650;
  margin-bottom: 10px;
}

</style>
